import type * as UserType from './type';
import { get, getList, post, put } from '@/utils/request';

// 学号密码登录
export const userLogin = (data: UserType.ILoginReq) => {
  return post<UserType.ILoginResData>({
    url: '/student/login',
    data,
  });
};

// 微信登录
export const userLoginByWechat = (data: UserType.ILoginReq) => {
  return post<UserType.ILoginResData>({
    url: '/student/login/wx',
    data,
  });
};

// 获取用户信息
export const getUserData = () => {
  return get<UserType.UserInfo>({
    url: '/student/getInfo',
  });
};

// 绑定微信
export const bindWeChat = (data: UserType.ILoginReq) => {
  return put<UserType.UserInfo>({
    url: '/student/bind/wx',
    data,
  });
};

// 解绑微信
export const unbindWeChat = (data: UserType.ILoginReq) => {
  return put<UserType.UserInfo>({
    url: 'student/unbind/wx',
    data,
  });
};

// 修改用户信息
export const updateUserInfo = (data: UserType.UserInfo) => {
  return put<UserType.UserInfo>({
    url: '/student/editInfo',
    data,
  });
};

// 修改密码
export const changePassword = (params: UserType.IModifyPasswordReq) => {
  return put<UserType.UserInfo>({
    url: '/student/changePassword',
    params,
  });
};

// 获取用户协议和隐私政策
export const getUserAgreement = (params: UserType.IUserLoginTermsReq) => {
  return getList<UserType.IUserLoginTermsResData[]>({
    url: '/common/config/list',
    params,
  });
};
